<?php
	foreach($result as $row){
				//echo ("hasil :".$row->intid_cabang."<br>");
				$query = $this->TampilkanFKC->get_finds_empty_cabang($row->intid_cabang);
				if($query->num_rows() > 0){
					$result1 = $this->TampilkanFKC->pengecekan_baby_nominal_differents($row->intid_cabang);	
					if($result1->num_rows() > 0){	
						foreach($result1->result() as $rod){
								$prs = $rod->nilai_persen;
							}	
					}else{
						$prs = 1;
						}
					
					$regD = 0;
					$hutD = 0;
					$har_hut = 0;
					$har_reg = 0;
					$reg_total = 0;
					$hut_total = 0;
									
					$omsetreg20=0;
					$omsetreg10=0;
					$omsetdealerreg=0;
					$omsethut20=0;
					$omsethut10=0;
					$omsetdealerhut=0;
					$calD=0;
					$har_cal=0;
					$omsetcal20=0;
					$omsetcal10=0;
					$omsetdealercal=0;
					$tinD=0;
					$har_tin=0;
					$omsettin20=0;
					$omsettin10=0;
					$omsetdealertin=0;
					$omsetifi=0;
					$omsetdealerifi=0;
					$ifiD=0;
					$har_ifi=0;
					$omsetifo10=0;
					$omsetdealerifo=0;
					$ifoD=0;
					$har_ifo=0;
					$omsetnet=0;
					$omsetdealernet=0;
					$netD=0;
					$har_net=0;
					$omsetsp=0;
					$omsetdealersp=0;
					$spD=0;
					$har_sp=0;
					$omsetp=0;
					$omsetdealerp=0;
					$pD=0;
					$har_p=0;
							
					//reguler
					$Reg = $this->Penjualan_model->get_reguler($row->intid_cabang, $bulan);
					$RegDealer = $this->Penjualan_model->get_reguler_dealer($row->intid_cabang, $bulan);

					//Hut
					$Hut = $this->Penjualan_model->get_hut($row->intid_cabang, $bulan);
					$HutDealer = $this->Penjualan_model->get_hut_dealer($row->intid_cabang, $bulan);
					
					//Challenge
					$Cal = $this->Penjualan_model->get_cal($row->intid_cabang, $bulan);
					$CalDealer = $this->Penjualan_model->get_cal_dealer($row->intid_cabang, $bulan);
					
					//Trade In
					$tin = $this->Penjualan_model->get_tin($row->intid_cabang, $bulan);
					$tinDealer = $this->Penjualan_model->get_tin_dealer($row->intid_cabang, $bulan);
					
					//1 Free 1 Hut
					$ifi = $this->Penjualan_model->get_ifi($row->intid_cabang, $bulan);
					$ifiDealer = $this->Penjualan_model->get_ifi_dealer($row->intid_cabang, $bulan);
					
					//1 Free 1 
					$ifo = $this->Penjualan_model->get_ifo($row->intid_cabang, $bulan);
					$ifoDealer = $this->Penjualan_model->get_ifo_dealer($row->intid_cabang, $bulan);

					//Netto 
					$net = $this->Penjualan_model->get_net($row->intid_cabang, $bulan);
					$netDealer = $this->Penjualan_model->get_net_dealer($row->intid_cabang, $bulan);
					
					//SpecialPrice 
					$sp = $this->Penjualan_model->get_sp($row->intid_cabang, $bulan);
					$spDealer = $this->Penjualan_model->get_sp_dealer($row->intid_cabang, $bulan);
					
					//Point 
					$p = $this->Penjualan_model->get_p($row->intid_cabang, $bulan);
					$pDealer = $this->Penjualan_model->get_p_dealer($row->intid_cabang, $bulan);

					$getFeeSc = $this->Penjualan_model->get_dealer_cabang($row->intid_cabang, $bulan);
					$data_cabang = $this->Penjualan_model->get_cabang($row->intid_cabang);
					
?>
<tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <?php
				$regD = 0;
				$hutD = 0;
				$har_hut = 0;
				$har_reg = 0;
				$reg_total = 0;
				$hut_total = 0;
								
				$omsetreg20=0;
				$omsetreg10=0;
				$omsetdealerreg=0;
				foreach ($Reg as $row):
					     $omsetreg20= $omsetreg20 + $row->TGroup20;
						 $omsetreg10= $omsetreg10 + $row->TGroup10;
				endforeach;	
				foreach ($RegDealer as $row1):
					     $omsetdealerreg= $omsetdealerreg + $row1->RegDealer;
				endforeach;	 
				?>
                <tr>
                	<td><?php echo $data_cabang->strkepala_cabang?></td>
                    <td><?php echo 'PIMPINAN';?></td>
                    <td><?php echo $data_cabang->strnama_cabang?></td>
                    <td>Reguler</td>
					
                    <td align="center"><?php echo (empty($omsetreg20))?'0':number_format($omsetreg20)?></td>
                    <td align="center"><?php echo (empty($omsetreg10))?'0':number_format($omsetreg10)?></td>
                    <td align="center">0</td>
                    <td align="center"><?php 
					$hdealer = ($omsetreg20 - ($omsetreg20*0.2)) + ($omsetreg10 - ($omsetreg10*0.1));
					echo (empty($hdealer))?'0':number_format($hdealer)?></td>
                    <td align="center"><?php echo (empty($hdealer))?'0':number_format(($hdealer) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($hdealer))?'0':number_format(($hdealer * $prs/100) * 5/100)?></td>
                    <td align="center"><?php 
					
					if(!empty($hdealer)){
						$regD = $hdealer;
						$har_reg =  (($hdealer) * $prs/100) - (($hdealer* $prs/100) * 5/100);
					
						echo (empty($har_reg))?'0':number_format($har_reg);
					}
					
					?></td>
                </tr>
                <?php 
				$omsethut20=0;
				$omsethut10=0;
				$omsetdealerhut=0;
				foreach ($Hut as $row2):
					     $omsethut20= $omsethut20 + $row2->TGroup20;
						 $omsethut10= $omsethut10 + $row2->TGroup10;
				endforeach;	
				foreach ($HutDealer as $row3):
					     $omsetdealerhut= $omsetdealerhut + $row3->HutDealer;
				endforeach;	 
				?>
                <tr>
                	<td><?php //echo $prs." persen";?></td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>Chall Hut</td>
                    <td align="center"><?php echo (empty($omsethut20))?'0':number_format($omsethut20)?></td>
                    <td align="center"><?php echo (empty($omsethut10))?'0':number_format($omsethut10)?></td>
                    <td align="center">0</td>
                    <td align="center"><?php $hdealerhut = ($omsethut20 - ($omsethut20*0.2)) + ($omsethut10 - ($omsethut10*0.1));
					echo (empty($hdealerhut))?'0':number_format($hdealerhut)?></td>
                    <td align="center"><?php echo (empty($hdealerhut))?'0':number_format(($hdealerhut) * $prs/100); $fhut=($hdealerhut * $prs)/100;?></td>
                    <td align="center"><?php echo (empty($hdealerhut))?'0':number_format(($fhut*5)/100);?></td>
                    <td align="center"><?php 
					
					if(!empty($hdealerhut)){
						$hutD = $hdealerhut;
						$har_hut = (($hdealerhut) * $prs/100) - (($hdealerhut* $prs/100) * 5/100);
						echo (empty($har_hut))?'0':number_format($har_hut);
					}
					?></td>
                </tr>
                <?php 
				$omsettulipcal20=0;
				$omsettulipcal10=0;
				$omsetdealercal=0;
				foreach ($Cal as $row4):
					     $omsettulipcal20= $omsettulipcal20 + $row4->TGroup20;
						 $omsettulipcal10= $omsettulipcal10 + $row4->TGroup10;
				endforeach;	
				foreach ($CalDealer as $row5):
					     $omsetdealercal= $omsetdealercal + $row5->CalDealer;
				endforeach;	 
				?>
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>Challenge</td>
                    <td align="center"><?php echo (empty($omsettulipcal20))?'0':number_format($omsettulipcal20)?></td>
                    <td align="center"><?php echo (empty($omsettulipcal10))?'0':number_format($omsettulipcal10)?></td>
                    <td align="center">0</td>
                    <td align="center"><?php $hdealercal = ($omsettulipcal20 - ($omsettulipcal20*0.2)) + ($omsettulipcal10 - ($omsettulipcal10*0.1));
					echo (empty($hdealercal))?'0':number_format($hdealercal)?></td>
                    <td align="center"><?php echo (empty($hdealercal))?'0':number_format(($hdealercal) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($hdealercal))?'0':number_format(($hdealercal * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$calD=0;
					$har_cal=0;
					if(!empty($hdealercal)){
						$calD = $hdealercal;
						$har_cal = (($hdealercal) * $prs/100) - (($hdealercal* $prs/100) * 5/100);
						echo (empty($har_cal))?'0':number_format($har_cal);
					}
					?></td>
                </tr>
                <?php 
				$omsettin20=0;
				$omsettin10=0;
				$omsetdealertin=0;
				//tgl 14 agustus 2013 pengubahan dengan menambahkan Total_Omset untuk menghitung data yang valid dan menampilkan nya dipenjualan omset10. mengganti TGroup10 dengan Total_Omset
				foreach ($tin as $row6):
					     $omsettin20= $omsettin20 + $row6->TGroup20;
						 //$omsettin10= $omsettin10 + $row6->TGroup10;
						 $omsettin10= $omsettin10 + $row6->Total_Omset;
				endforeach;	
				foreach ($tinDealer as $row7):
					     $omsetdealertin= $omsetdealertin + $row7->tinDealer;
				endforeach;	 
				?>
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>Trade In</td>
                    <td align="center"><?php echo (empty($omsettin20))?'0':number_format($omsettin20)?></td>
                    <td align="center"><?php echo (empty($omsettin10))?'0':number_format($omsettin10)?></td>
                    <td align="center">0</td>
                    <td align="center"><?php $hdealertin = ($omsettin20 - ($omsettin20*0.2)) + ($omsettin10 - ($omsettin10*0.1));
					echo (empty($hdealertin))?'0':number_format($hdealertin)?></td>
                    <td align="center"><?php echo (empty($hdealertin))?'0':number_format(($hdealertin) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($hdealertin))?'0':number_format(($hdealertin * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$tinD=0;
					$har_tin=0;
					if(!empty($hdealertin)){
						$tinD = $hdealertin;
						$har_tin = (($hdealertin) * $prs/100) - (($hdealertin* $prs/100) * 5/100);
						echo (empty($har_tin))?'0':number_format($har_tin);
					}
					?></td>
                </tr>
                <?php 
				$omsetifi=0;
				$omsetdealerifi=0;
				foreach ($ifi as $row8):
					     $omsetifi= $omsetifi + $row8->inttotal_omset;
				endforeach;	
				foreach ($ifiDealer as $row9):
					     $omsetdealerifi= $omsetdealerifi + $row9->ifiDealer;
				endforeach;	 
				?>
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>1 Free 1 Hut/Nett</td>
                    <td align="center">0</td>
                  <td align="center">0</td>
                    <td align="center"><?php echo (empty($omsetifi))?'0':number_format($omsetifi)?></td>
                    <td align="center"><?php echo (empty($omsetdealerifi))?'0':number_format($omsetdealerifi)?></td>
                    <td align="center"><?php echo (empty($omsetdealerifi))?'0':number_format(($omsetdealerifi) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($omsetdealerifi))?'0':number_format(($omsetdealerifi * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$ifiD=0;
					$har_ifi=0;
					if(!empty($omsetdealerifi)){
						$ifiD = $omsetdealerifi;
						$har_ifi = (($omsetdealerifi) * $prs/100) - (($omsetdealerifi* $prs/100) * 5/100);
						echo (empty($har_ifi))?'0':number_format($har_ifi);
					}
					?></td>
                </tr>
                 <?php 
				$omsetifo10=0;
				$omsetdealerifo=0;
				foreach ($ifo as $row10):
					     $omsetifo10= $omsetifo10 + $row10->TGroup10;
				endforeach;	
				foreach ($ifoDealer as $row11):
					     $omsetdealerifo= $omsetdealerifo + $row11->ifoDealer;
				endforeach;	 
				?>
                 <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>1 Free 1 10%</td>
                    <td align="center">0</td>
                    <td align="center"><?php echo (empty($omsetifo10))?'0':number_format($omsetifo10)?></td>
                    <td align="center">0</td>
                    <td align="center"><?php $hdealerifo = ($omsetifo10 - ($omsetifo10*0.1));
					echo (empty($hdealerifo))?'0':number_format($hdealerifo)?></td>
                    <td align="center"><?php echo (empty($hdealerifo))?'0':number_format(($hdealerifo) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($hdealerifo))?'0':number_format(($hdealerifo * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$ifoD=0;
					$har_ifo=0;
					if(!empty($hdealerifo)){
						$ifoD = $hdealerifo;
						$har_ifo = (($hdealerifo) * $prs/100) - (($hdealerifo* $prs/100) * 5/100);
						echo (empty($har_ifo))?'0':number_format($har_ifo);
					}
					?></td>
                </tr>
                <?php 
				$omsetnet=0;
				$omsetdealernet=0;
				foreach ($net as $row12):
					     $omsetnet= $omsetnet + $row12->inttotal_omset;
				endforeach;	
				foreach ($netDealer as $row13):
					     $omsetdealernet= $omsetdealernet + $row13->netDealer;
				endforeach;	 
				?>
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>Netto</td>
                    <td align="center">0</td>
                    <td align="center">0</td>
                    <td align="center"><?php echo (empty($omsetnet))?'0':number_format($omsetnet)?></td>
                    <td align="center"><?php echo (empty($omsetdealernet))?'0':number_format($omsetdealernet)?></td>
                    <td align="center"><?php echo (empty($omsetdealernet))?'0':number_format(($omsetdealernet) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($omsetdealernet))?'0':number_format(($omsetdealernet * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$netD=0;
					$har_net=0;
					if(!empty($omsetdealernet)){
						$netD = $omsetdealernet;
						$har_net = (($omsetdealernet) * $prs/100) - (($omsetdealernet* $prs/100) * 5/100);
						echo (empty($har_net))?'0':number_format($har_net);
					}
					?></td>
                </tr>
                <?php 
				$omsetsp=0;
				$omsetdealersp=0;
				foreach ($sp as $row14):
					     $omsetsp= $omsetsp + $row14->inttotal_omset;
				endforeach;	
				foreach ($spDealer as $row15):
					     $omsetdealersp= $omsetdealersp + $row15->netDealer;
				endforeach;	 
				?>
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>Special Price</td>
                    <td align="center">0</td>
                    <td align="center">0</td>
                    <td align="center"><?php echo (empty($omsetsp))?'0':number_format($omsetsp)?></td>
                    <td align="center"><?php echo (empty($omsetdealersp))?'0':number_format($omsetdealersp)?></td>
                    <td align="center"><?php echo (empty($omsetdealersp))?'0':number_format(($omsetdealersp) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($omsetdealersp))?'0':number_format(($omsetdealersp * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$spD=0;
					$har_sp=0;
					if(!empty($omsetdealersp)){
						$spD = $omsetdealersp;
						$har_sp = (($omsetdealersp) * $prs/100) - (($omsetdealersp* $prs/100) * 5/100);
						echo (empty($har_sp))?'0':number_format($har_sp);
					}
					?></td>
                </tr>
                <?php 
				$omsetp=0;
				$omsetdealerp=0;
				foreach ($p as $row16):
					     $omsetp= $omsetp + $row16->inttotal_omset;
						 
				endforeach;	
				foreach ($pDealer as $row31):
					     $omsetdealerp= $omsetdealerp + $row31->netDealer;
				endforeach;	 
				?>
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>Point</td>
                    <td align="center">0</td>
                    <td align="center">0</td>
                    <td align="center"><?php echo (empty($omsetp))?'0':number_format($omsetp)?></td>
                    <td align="center"><?php echo (empty($omsetdealerp))?'0':number_format($omsetdealerp)?></td>
                    <td align="center"><?php echo (empty($omsetdealerp))?'0':number_format(($omsetdealerp) * $prs/100)?></td>
                    <td align="center"><?php echo (empty($omsetdealerp))?'0':number_format(($omsetdealerp * $prs/100)*5/100)?></td>
                    <td align="center"><?php 
					$pD=0;
					$har_p=0;
					if(!empty($omsetdealerp)){
						$pD = $omsetdealerp;
						$har_p = (($omsetdealerp) * $prs/100) - (($omsetdealerp* $prs/100) * 5/100);
						echo (empty($har_p))?'0':number_format($har_p);
					}
					?></td>
                </tr>
                <?php
				$tab0 = $tab0+ $omsetp;
					$tab5 = $tab5 + $omsetdealerp;
					$tab1 = $tab1 + ($regD + $hutD + $calD + $tinD + $ifiD + $ifoD + $netD + $spD + $pD);
					$tab2 = $tab2 + (($regD * $prs / 100) + ($hutD * $prs / 100) + ($calD * $prs/ 100) + ($tinD * $prs/ 100)+ ($ifiD * $prs/ 100)+ ($ifoD * $prs/ 100)+ ($netD * $prs/ 100) + ($spD * $prs/ 100) + ($pD * $prs/ 100));
					$tab3 = $tab3 + ((($regD * $prs/100) * 5/100) + (($hutD * $prs/100)*5/100) + (($calD * $prs/100) * 5/ 100) + (($tinD * $prs/100 )* 5/ 100)+ (($ifiD * $prs/100) * 5/ 100)+ (($ifoD * $prs/100) * 5/ 100)+ (($netD * $prs/100) * 5/ 100) + (($spD * $prs/100) * 5/ 100) + (($pD * $prs/100) * 5/ 100));
					$tab4 = $tab4 + ($har_hut + $har_reg + $har_cal + $har_tin + $har_ifi+ $har_ifo+ $har_net + $har_sp + $har_p);
				}
}				
				?>
					<tr class="detail">
                	<td colspan="6">TOTAL FEE CABANG</td>
                    
                    <td align="center">&nbsp;</td>
                    <td align="center"><?php echo $tab1; ?></td>
                    <td align="center"><?php echo $tab2;?></td>
                    <td align="center"><?php echo $tab3;?></td>
 					<td align="center"><?php echo $tab4;?></td>
                </tr>